// pages/loupan/ershoulist.js
var app =getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		ershou: '',
		limit:7,
		searchvalue:'',
    showmenu1: true,
    showmenu2: true,
    showmenu3: true,
    showmenu4: true,
    searchlimit:5,
    searchbnt: false
	},

	/**
	 * 生命周期函数--监听页面加载
	 */



	onLoad: function (options) {
		var limit =this.data.limit
		this.ershou(limit);
	},
	ershou(limit) {
    wx.showLoading({
      title: '加载中',
    })
		var that = this;
		var setid = app.globalData.cityCode;
		app.core('get', 'get_old_more_list/site_id/' + setid +'/limit/'+limit+'', {},
			(res) => {
				console.log(res, 'ershou')
				var arr = res.data;
				for (var i = 0; i < arr.length; i++) {
					switch (arr[i].propertyType) {
						case 1:
							arr[i].propertyType = '住宅'
							break;
						case 2:
							arr[i].propertyType = '商铺'
							break;
						case 3:
							arr[i].propertyType = '写字楼'
							break;
					}
					if (arr[i].fitment == 1) {
						arr[i].fitment = '毛坯'
					} else if (arr[i].fitment == 2) {
						arr[i].fitment = '普通装修'
					}
					else if (arr[i].fitment == 3) {
						arr[i].fitment = '精装修'
					}
					else {
						arr[i].fitment = '其他'
					}
				}
				that.setData({
					ershou: arr,
					limit:limit+5
				})
      wx.hideLoading()
			}
		)
	},// 二手楼盘
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		var limit = this.data.limit
    var that =this
    var type = that.data.searchbnt;
    var searchlimit = that.data.searchlimit;
    if(type == false){
      this.ershou(limit)
    }
    else{

      var searchvalue = that.data.searchvalue;
      that.searchlistsss(searchvalue, searchlimit);
      console.log(222)
    }
	
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	},

	searchlist(e) {
		this.setData({
			searchvalue: e.detail.value
		})
	},

	searchdesc() {

		var that = this;
		var setid = app.globalData.cityCode;
		var searchvalue = that.data.searchvalue;
		if (searchvalue == '') {
			wx.showToast({
				title: '请输入内容',
				duration: 1000,
				icon: 'none'
			})
		} else {
		that.searchlistsss(searchvalue,6)
		}

	},

  searchlistsss(searchvalue, limit) {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    var setid = app.globalData.cityCode;
    app.core('get', 'get_oldhouse_list/site_id/' + setid + '/limit/' + limit + '', {
      keywords: searchvalue
    }, (res) => {
      console.log(res)
		if(res.data.length !=0){
      var arr = res.data;
      for (var i = 0; i < arr.length; i++) {
        switch (arr[i].propertyType) {
          case 1:
            arr[i].propertyType = '住宅'
            break;
          case 2:
            arr[i].propertyType = '商铺'
            break;
          case 3:
            arr[i].propertyType = '写字楼'
            break;
        }
        if (arr[i].fitment == 1) {
          arr[i].fitment = '毛坯'
        } else if (arr[i].fitment == 2) {
          arr[i].fitment = '普通装修'
        }
        else if (arr[i].fitment == 3) {
          arr[i].fitment = '精装修'
        }
        else {
          arr[i].fitment = '其他'
        }
      }
			that.setData({
				searchbnt: true,
				searchlimit: limit + 5,
        ershou: arr
			})
		}else{
			wx.showToast({
				title: '暂无更多内容',
				duration:1000,
				icon:'none'
			})
		}
 
      wx.hideLoading()
    })
  },

})